import java.util.Scanner;

public class TestDemo {
    //模拟密码登录
    public static void main5(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int count = 3;//三次登录机会
        while(count != 0){
            System.out.println("请输入密码:>");
            String password = scanner.nextLine();//输入密码
            if(password.equals("12345678")){
                System.out.println("登录成功！");
                break;
            }
            System.out.println("密码错误，请重新尝试！");
            count--;
            System.out.println("你还有" + count + "次机会！");
        }
        if(count == 0){
            System.out.println("登录失败！");
        }
        scanner.close();//关闭Scanner
    }
    //计算阶乘和
    public static int fac(int num){//计算阶乘
        int fac = 1;
        for(int i = 1;i <= num;i++){
            fac *= i;
        }
        return fac;
    }
    public static int facSum(int num){//计算和
        int sum = 0;
        for(int i = 1;i <= num;i++){
            sum += fac(i);
        }
        return sum;
    }
    public static void main4(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        int sum = facSum(num);
        System.out.println(num + "的阶乘和为" + sum);
        scanner.close();
    }
    //二进制中1的个数
    public static int binaryOne(int num){
        int count = 0;
        for(int i = 0;i < 32;i++){
            if((num & 1) == 1){
                count++;
            }
            num >>>= 1;//无符号右移，防止负数问题
        }
        return count;
    }
    public static void main3(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        int count = binaryOne(num);
        System.out.println(num + "的二进制中共有" + count + "个1");
        scanner.close();
    }
    //水仙花数
    public static  boolean  narcissisticNumber(int n){
        int sum = 0;
        int m = n;//复制
        while(n > 0){
            if(n % 10 > 0){
                sum += Math.pow(n%10,3);
            }
            n /= 10;
        }
        if(sum == m){
            return true;
        }
        return false;
    }
    public static void main2(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        for(int i = 1;i <= num;i++){
            if(narcissisticNumber(i) == true){
                System.out.print(i + " ");
            }
        }
        scanner.close();
    }
    //打印X型图案，多组输入
    public static void main1(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while(scanner.hasNext()){
            int line = scanner.nextInt();//控制行
            for(int i = 0;i < line;i++){
                for(int j = 0;j < line;j++){
                    if(j == i || j == line - 1 - i){
                        System.out.print("*");
                    }
                    else{
                        System.out.print(" ");
                    }
                }
                System.out.println();//换行
            }
        }
    }
}
